<?php
class BaseModelFront extends BaseModel
{

    public function __construct()
    {
        parent::__construct();
        /*
        if ($this->table)
        {
            $strSql = 'DESC ' . $this->table;
            $arrRows = $this->db()->query($strSql);
            foreach ($arrRows as $item)
            {
                $this->fields[] = $item['Field'];
            }
        }
        */
    }

    public function db()
    {
        if(!isset(self::$db))
        {
            $config = Yii::app()->params['dbconf_front'];//Config :: $mysqlConfig;
            $balance = mt_rand(1,count($config['machine']));
            $handle = ConnectionMan::getMysqli($selServer, $config['machine'],$config['auth'],
                $config['talk']['connect_timeout_ms'],$config['talk']['strategy'], $balance);
            if($handle != false)
            {
                self::$db = new DB(false,$handle);
                self::$db->query('set names utf8');
                // 去掉对批量操作的安全检查
                //self::$db->addHook(DB::HK_AFTER_QUERY,1,array('BaseModel','riskCheck'));
                self::$db->autoCommit(false);
                register_shutdown_function(array(self::$db,'commit'));
            }
            else{
                //logging
                Yii::log('connect db failed','error');
            }
        }
        
        return self::$db;
    }

}
